import request from "@/utils/request";

const TAG_BASE_URL = "/api/admin";

const TagAPI = {
  // 获取标签名称数据
  getTagName() {
    return request<any, TagName[]>({
      url: `${TAG_BASE_URL}/tagName`,
      method: "get",
    });
  },

  // 编辑标签
  editTagData(newTagData: NewTagData) {
    return request<any, any>({
      url: `${TAG_BASE_URL}/editTag`,
      method: "put",
      data: newTagData,
    });
  },

  // 获取编辑标签的数据
  editedTagData(tag_id: number) {
    return request<any, NewTagData>({
      url: `${TAG_BASE_URL}/editedTag`,
      method: "get",
      params: { tag_id },
    });
  },

  // 删除选中标签
  delSelTagData(tag_ids: number[]) {
    return request<any, any>({
      url: `${TAG_BASE_URL}/delSelTag`,
      method: "delete",
      data: { tag_ids },
    });
  },

  // 删除标签
  delTagData(tag_id: number) {
    return request<any, any>({
      url: `${TAG_BASE_URL}/delTag`,
      method: "delete",
      data: { tag_id },
    });
  },

  // 校验标签名是否重复
  verifyTagName(tag_id: number, tag_name: string) {
    return request<any, any>({
      url: `${TAG_BASE_URL}/verify`,
      method: "get",
      params: { tag_id, tag_name },
    });
  },

  // 添加标签
  addTagData(newTagData: NewTagData) {
    return request<any, any>({
      url: `${TAG_BASE_URL}/addTag`,
      method: "post",
      data: newTagData,
    });
  },

  // 获取标签的数据和数量
  getTag(page: number, pagesize: number, tag_name: string, is_show: number | string) {
    return request<any, TagDataCount>({
      url: `${TAG_BASE_URL}/tag`,
      method: "get",
      params: { page, pagesize, tag_name, is_show },
    });
  },
};

export default TagAPI;

// 标签名称数据
export interface TagName {
  tag_id: number;
  tag_name: string;
}

// 搜索的数据类型
export interface SearchData {
  tag_name: string;
  is_show: string | number;
}

// 添加的标签的数据
export interface NewTagData {
  tag_id: number;
  tag_name: string;
  is_show: boolean | number;
}

// 获取的标签数据和数量的类型
export interface TagDataCount {
  tagData: TagData[];
  tagCount: number;
}

// 获取的标签数据的类型
export interface TagData {
  tag_id: number;
  tag_name: string;
  is_show: number;
}
